<?php

namespace app\admin\controller;

use think\Request;
use app\common\lib\Upload;

/********
 * 后台图片上传逻辑
 */
class Image extends Base
{
    /********
     * 图片上传
     */
    public function upload1()
    {
        $file = request()->file('file');

        $info = $file->move('uploads');
        if ($info && $info->getpathName()) {
            $data = [
                'status' => 1,
                'message' => 'OK',
                'data' => '/' . $info->getpathName(),
            ];
            echo  json_encode($data);
            exit;
        }
        echo json_encode(['status' => 0, 'message' => '上传失败']);
        exit;
    }

    /**
     * 七牛图片上传
     *
     *
     */
    public function upload()
    {
        try {
            $image = Upload::image();
        } catch (\Exception $e) {
            echo json_encode(['status' => 0, 'message' => $e->getMessage()]);
        }
        if ($image) {
            $data = [
                'status' => 1,
                'message' => 'OK',
                'data' => config('qiniu.image_url') . '/' . $image,
            ];
            echo json_encode($data);
            exit;
        } else {
            echo json_encode(['status' => 0, 'message' => '上传失败']);
        }
    }
}
